package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import db.DBConnecter;

import entity.Account;
import flex.messaging.io.ArrayList;

public class AccountDAO {
	private DBConnecter db;
	public AccountDAO() {
		db = new DBConnecter();//initialize a new connection
	}
	public List<Account> queryAccounts(String userid){
		ResultSet rs;
		List<Account> accounttList = new ArrayList();
		String sql = "select * from account where acc_cst_id = '"+userid+"' ";
		
		try{
			rs = db.query(sql);
			while(rs.next()){
				Account account = new Account();
				account.setAcc_credit(rs.getString("acc_credit"));
				account.setAcc_cst_id(rs.getString("acc_cst_id"));
				account.setAcc_id(rs.getString("acc_id"));
				account.setAcc_password(rs.getString("acc_password"));
				account.setAcc_state(rs.getString("acc_state"));
				account.setAcc_type(rs.getString("acc_type"));
				accounttList.add(account);
			}
			System.out.println("accounttList.size"+accounttList.size());
			rs.close();
			db.close();
			return accounttList;
			
		}catch(SQLException e){
			e.printStackTrace();
			db.close();
			return accounttList;
		}
		
		
		
	}
}
